function ThunderPart() {

	var thunderFault = [];// [[时间，原因]]
	var thunderRecord = [];// [[时间，次数]]
	var thunderSum = 0;

	var thunderTable;
	this.load = function() {
		initThunderDatas();
	};
	function initThunderDatas() {
		initThunderFault();
		initThunderRecord();
		initThunderRadius();
	}
	function initThunderFault() {
		$.getJSON('/rest/thunder/getThunderFaultByLineId/' + lineId, function(
				result) {
			thunderFault = result;
			initThunderFaultTable();
		});
	}
	function initThunderRecord() {
		$.getJSON('/rest/thunder/getThunderByLineId/' + lineId,
				function(result) {
					thunderRecord = result;
					initThunderRecordChart();
				});
	}
	function initThunderRadius() {
		$.getJSON('/rest/thunder/getThunderRadius', function(result) {
			$('#thunderRadius').html(result);
		});
	}
	function getChartData() {
		var chartData = [];
		thunderRecord = getSort(thunderRecord, 0);
		if (thunderRecord.length > 0) {
			for (var i = 0; i < thunderRecord.length - 1; i++) {
				chartData.push([ new Date(thunderRecord[i][0]),
						thunderRecord[i][1] ]);
				if (thunderRecord[i][1] > 0) {
					thunderSum++;
				}
			}
			chartData
					.push([ new Date(thunderRecord[i][0]), thunderRecord[i][1] ]);
		}
		return chartData;
	}
	function initThunderRecordChart() {
		var chartData = getChartData();
		$('#thunderSum').html("共计" + thunderSum + "天");
		$('#thunderNum').html(thunderSum);
		if (thunderSum == 0) {
			$('#thunderChart').html('无数据');
			$('#thunderChart').addClass('no-data');
		} else {
			thunderChart = new CategoryLine('thunderChart');
			thunderChart.setxAxisTitle("时间").setyAxis(chartData).setyAxisName(
					"雷击次数").setyAxisTitle("次");
			thunderChart.addColor([ "#FFA07A" ]).setDataZoom(true).setDataView(
					false).setMagicType(false);

			var option = thunderChart.getOption();
			option.color = [ '#FFA07A' ];
			option.xAxis.type = 'time';
			option.dataZoom = [ {
				type : 'inside'
			}, {
				type : 'slider',
				dataBackground : {
					lineStyle : {
						color : '#FFA07A',
						opacity : 1
					}
				}
			} ];

			var series = option.series[0];
			series.label.normal.show = false;
			series.label.emphasis.show = true;
			series.label.emphasis.position = 'top';
			series.showSymbol = false;
			// series.areaStyle = {'normal':{'color':'rgba(188,247,241,1)'}};
			thunderChart.show();
		}
	}
	function initThunderFaultTable() {
		$('#thunderFaultSum').html("共计" + thunderFault.length + "次");
		$('#thunderFaultNum').html(thunderFault.length);

		var columns = ['序号','故障时间', '故障类型','故障过程','备注' ];
		var opt = MyTable.getDefaultOptions();
		opt.paging = true;
		opt.pageLength = 5;
		thunderTable = new MyTable("thunderTable", columns, opt);
		var dataset = [];
		for ( var i in thunderFault) {
			var f = thunderFault[i];
			var dt = [Number(i)+1,DateUtil.dateTime(f.faultTime),str(f.faultType),str(f.description),str(f.remark)];
			dataset.push(dt);
		}
		thunderTable.setDataSet(dataset);
		thunderTable.show();
		
		function str(s){
			return s?s:"";
		}
	}
	// 将[[],[],]按照index的顺序从小到大排序
	function getSort(array, index) {
		array.sort(compare);
		function compare(obj1, obj2) {
			if (obj1 == undefined || obj1[index] == undefined
					|| obj1[index] == null) {
				return -1;
			}
			if (obj2 == undefined || obj1[index] == undefined
					|| obj1[index] == null) {
				return 1;
			}
			if (obj1[index] < obj2[index]) {
				return -1;
			} else {
				return 1;
			}
		}
		return array;
	}
	function initDisc() {
		var thunderNum = document.getElementById('thunderNum');
		var thunderFaultNum = document.getElementById('thunderFaultNum');
		thunderNum.innerHTML = "雷击    " + (thunder.length - fault.length) + "次";
		thunderFaultNum.innerHTML = "雷击故障    " + fault.length + "次";
	}
	this.resizeHtml = function(){
		if (thunderChart) {
			thunderChart.getChart().resize();
		}
		if(thunderTable){
			thunderTable.getTable().draw();
		}
	}
}
